home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / port / isc / flock.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  649b  |  33 lines

  1. /* flock emulation for System V using fcntl
  2.  *
  3.  * flock is just mapped to fcntl 
  4.  */
  5.  
  6. #include <unistd.h>
  7. #include <fcntl.h>
  8. #include <errno.h>
  9. #include <net/errno.h>
  10.  
  11. #include "port.h"
  12.  
  13. int
  14. flock(int fd, int operation)
  15. {
  16.     struct flock flock;
  17.     int r;
  18.     
  19.     memset(&flock, '\0', sizeof(flock));
  20.     if (operation & LOCK_EX)
  21.     flock.l_type = F_WRLCK;
  22.     else if (operation & LOCK_SH)
  23.     flock.l_type = F_RDLCK;
  24.     else
  25.     flock.l_type = F_UNLCK;
  26.     flock.l_whence = SEEK_SET;
  27.     
  28.     if (((r=fcntl(fd, (operation & LOCK_NB) ? F_SETLK:F_SETLKW, &flock)) == -1)
  29.         && (errno == EACCES || errno == EAGAIN))
  30.             errno = EWOULDBLOCK;
  31.     return r;
  32. }
  33.